package cn.gxa.j229.bug.finance.controller.loanuser;

import cn.gxa.j229.bug.finance.pojo.Audit;
import cn.gxa.j229.bug.finance.service.loanuser.AuditService;
import cn.gxa.j229.bug.finance.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: fenglin
 * @Date:2020/9/27 17:27
 * @Version 1.0
 */
@Controller
@RequestMapping("/audit")
public class AuditConroller {

    @Autowired
    AuditService auditService;

    JsonResult jsonResult=new JsonResult();


    @PostMapping("/selectAll")
    @ResponseBody
    public Map selectAll(@RequestBody Audit audit){

        List<Map<String, String>> selectAll = auditService.selectAll(audit);
        int count = auditService.selectAllCount(audit);
        jsonResult.put("count",count);
        jsonResult.setData(selectAll);
        jsonResult.setMsg("成功");
        jsonResult.setCode("200");
        return jsonResult.getValues();
    }
    @PostMapping("/selectKey")
    @ResponseBody
    public Map selectKey(@RequestBody Audit audit){
        Date startDate = audit.getStartDate();
        System.out.println(startDate);

        List<Map<String, String>> selectKey = auditService.selectKey(audit);
      int count = auditService.selectKeyCount(audit);
        jsonResult.put("count",count);
        jsonResult.setData(selectKey);
        jsonResult.setMsg("成功");
        jsonResult.setCode("200");
        return jsonResult.getValues();
    }



    @PostMapping("/updateByPrimaryKey")
    @ResponseBody
    public Map updateByPrimaryKey(@RequestBody Audit audit){

            int updateByPrimaryKey = auditService.updateByPrimaryKey(audit);
            jsonResult.setData(updateByPrimaryKey);
            jsonResult.setMsg("更新成功");
            jsonResult.setCode("200");

        return jsonResult.getValues();
    }

    @PostMapping("/insert")
    @ResponseBody
    public Map insert(@RequestBody Audit audit){
        int insert = auditService.insert(audit);
        jsonResult.setData(insert);
        jsonResult.setMsg("插入成功");
        jsonResult.setCode("200");
        return jsonResult.getValues();
    }

}
